﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2023_09_13
{
    internal class _7
    {
        static int n, A, B;
        static int[] a, b, c;

        public static int MaxDelicious(int index, int remainingA, int remainingB)
        {
            if (index == n || remainingA == 0 || remainingB == 0) return 0;

            int notChosen = MaxDelicious(index + 1, remainingA, remainingB);

            int chosen = 0;
            if (remainingA >= a[index] && remainingB >= b[index])
            {
                chosen = c[index] + MaxDelicious(index + 1, remainingA - a[index], remainingB - b[index]);
            }

            return Math.Max(notChosen, chosen);
        }

        public static void Main7()
        {
            var inputs = Console.ReadLine().Split();
            n = int.Parse(inputs[0]);
            A = int.Parse(inputs[1]);
            B = int.Parse(inputs[2]);

            a = new int[n];
            b = new int[n];
            c = new int[n];

            for (int i = 0; i < n; i++)
            {
                inputs = Console.ReadLine().Split();
                a[i] = int.Parse(inputs[0]);
                b[i] = int.Parse(inputs[1]);
                c[i] = int.Parse(inputs[2]);
            }

            Console.WriteLine(MaxDelicious(0, A, B));
        }
    }
}
